
#VPATH = 

# ........ makefile

MODEM_TYPE = MODEM_TYPE__MOTOROLA
#MODEM_TYPE = MODEM_TYPE__SIMCOM


ifeq ($(MODEM_TYPE), MODEM_TYPE__SIMCOM)
	MODEM_LABEL = smc
else
	MODEM_LABEL = m
endif

REVISION=$(shell svnversion | sed 's/.*://' | sed 's/M//')

#APP = car_pet_block
APP = inp_to_sms

Target = $(APP).$(MODEM_LABEL).r$(REVISION).hex

# SourceList = main.c my_macros.c Inputs.c Outputs.c ModemService.c Application.c Command.c Receivers.c USART.c 
# SourceList += string.c eeprom.c ex_eeprom.c DataMode.c Config.c Analog.c Revision.c PhoneNumbers.c 
# SourceList += InputsHandlers.c Status.c Passwords.c Const.c SysTime.c Interrupt.c Init.c SMS_Message.c 
# SourceList += Tools.c RF_RX.c AuxPort.c Revision.c Sys_Strings.c Debug.c RF_Manager.c RF_TX.c 
# SourceList += NeighborCells.c Print_SMS.c Car_PetrolBlocking.c #Translator.c

SourceList = main.c my_macros.c Inputs.c Outputs.c ModemService.c Application.c Command.c Receivers.c USART.c 
SourceList += string.c eeprom.c ex_eeprom.c Config.c Analog.c Revision.c #PhoneNumbers.c DataMode.c 
SourceList += Status.c Const.c SysTime.c Interrupt.c Init.c SMS_Message.c Tools.c RF_RX.c Passwords.c 
SourceList += InputsHandlers.c AuxPort.c Revision.c Sys_Strings.c Debug.c RF_Manager.c RF_TX.c 
SourceList += NeighborCells.c Print_SMS.c Car_PetrolBlocking.c 
SourceList += Translator.c fifo.c Events.c dev.c printf.c Print.c


CodeOffset = 0x3000
#Offset = 0x2600
PointerWidth = CP24

# SourceList = main.c my_macros.c SysClock.c Interrupt.c App.c String.c RF12B.c Init.c UART.c Outputs.c
# SourceList += Command.c printf.c Inputs.c Status.c mem.c
#MicroType = 16F690
#	MicroType = 18F25K20
MicroType = 18F6722

MACROS = -DAPP_DEBUG -DREVISION=$(REVISION) -D$(MODEM_TYPE) -D$(APP)

def f = pipe

#CC = C:/PROGRA~1/HI-TEC~1/PICC/std/9.60/bin/picc.exe
#CC = C:/PROGRA~1/HI-TEC~1/PICC/9.70/bin/picc.exe
#CC = C://PROGRA~1//HI-TEC~1//PICC-18//PRO//9.63//bin//picc18.exe 
CC = picc18

#	CFLAGS = --pass1 -P -q --runtime=default --opt=all -D__DEBUG=1 -g -Blarge --double=24 --cp=24
CFLAGS = --pass1 -P -q --runtime=default --opt=all -D__DEBUG=1 -g -Blarge --cp=24
CFLAGS +=  "--errformat=%f: %l: (%n) %s"
# CFLAGS += "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s"



LDFLAGS = --summary=default --output=default -P --runtime=default --opt=all -D__DEBUG=1 -g
LDFLAGS += "--errformat=%f: %l: (%n) %s" "--msgformat=Advisory[%n] %s" ### --codeoffset=$(CodeOffset)
# LDFLAGS +=  "--warnformat=Warning [%n] %f; %l.%c %s"

ObjectList = $(patsubst %.c, %.p1, $(SourceList)) 

$(Target) : $(ObjectList) 
	$(CC) $^ -O$@ $(LDFLAGS) --chip=$(MicroType) #-L-pSer_Num=0x06B0

# $(Target) : $(ObjectList) 
# 	$(CC) -E $^ -O$@ -Q -$(MicroType) -L-pSerNum=0x06B0
# #	WinPic800.exe -p -s -dPIC$(MicroType) $(Target)
# #	D:\PROGRA~1\Soft-Log\IcpWin\ICP_Win.exe $(Target) /p


# %.obj : %.c *.h
# 	$(CC) -C -E $< -O$@ -Zg9 -O -Q -$(MicroType)

%.p1 : %.c *.h
	$(CC) $< -O$@ -Q $(CFLAGS) $(MACROS) --chip=$(MicroType) 


c: 
	rm -f *.obj *.lst *.sdb *.p1 *.pre *.hxl *.sym *.rlf *.cof *.d
	rm -f $(Target) 

e:
	etags *.c *.h

serial: PIC18_Serialization.exe
	./PIC18_Serialization.exe $(Target)

p: $(Target) #serial 
	@echo "       ======== PROGRAMMING ============"
#C:/PK2CMD/pk2cmd.exe -W -V12 -PPIC$(MicroType) -E -F$(Target) -M -Y -K -I -R 
	pk2cmd -W -V12 -PPIC$(MicroType) -E -F$(Target) -M -Y -K -I -R 
#	C:\WinPic800\WinPic800.exe -p -s -dPIC$(MicroType) $(Target)
#	D:\PROGRA~1\Soft-Log\IcpWin\ICP_Win.exe $(Target) /p
#	pk2cmd -A5 -V12 -PPIC$(MicroType) -E -F$(Target) -M -Y -K -I


all: c $(Target)

ifeq ($(f),p)
prog: p
	echo
else
prog: 
	@echo
endif


b : $(Target) serial prog

ba: 
	./alld.sh



# QA_WORK_VER = Z:/Development/SimPhony_V3_QA/SimPhony_Versions/Work_Version

# alld: $(Target) smd
# 	bash $(VPATH)/CreateDir.sh $(QA_WORK_VER)
# 	cp $(Target) $(QA_WORK_VER) 
# 	bash ../Utilites/h2h.sh $(BOOT_LOADER) $(Target) > $(FULL)
# 	unix2dos $(FULL)
# 	cp $(FULL) $(QA_WORK_VER) 
# 	./CLEAN.BAT

# smd:
# #	echo $(QA_WORK_VER) | email -s "Versions Update - TEST-11" dimitrip@cellnets.com,dima.development@gmail.com
# 	bash ../SimPhony_Basic/sendEMail.sh $(QA_WORK_VER)


.PHONY : c e p b prog


